﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace CLab.Utils.Extensions
{
    public static class DataTableExtension
    {
        public static string ToXml(this System.Data.DataTable dt)
        {
            if (dt == null)
                return string.Empty;

            string xml="<tabla>";
            foreach (DataRow dr in dt.Rows)
            {
                xml = xml + "<renglon>";
                foreach (DataColumn c in dt.Columns)
                {
                    xml = xml + "<" + c.ColumnName + ">" + dr[c.ColumnName] + "</" + c.ColumnName + ">";
                }

                xml = xml + "</renglon>";
            }

            return xml + "</tabla>";
        }
    }
}